package com.jurenzhao.partssystem.business.order_temporary.controller;

import com.jurenzhao.partssystem.business.order_temporary.dao.CarseriesMapper;
import com.jurenzhao.partssystem.business.order_temporary.entity.*;
import com.jurenzhao.partssystem.business.order_temporary.service.ShoppingService;
import org.apache.ibatis.jdbc.Null;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/shopping")
public class ShoppingController {

    @Resource
    private ShoppingService shoppingService;


    @RequestMapping("/test")
    public String test(Model model){
        List<Carseries> seriesList = shoppingService.list();
        model.addAttribute("seriesList",seriesList);
        return "/Business/Order_Temporary/ShoppingcarList";
    }

    @ResponseBody
    @RequestMapping("/modelList")
    public List<Carmodel> modelList(Model model, String seriesId){
        List<Carmodel> carmodelList = shoppingService.modellist(seriesId);
        return carmodelList;
    }

    @ResponseBody
    @RequestMapping("/pieceList")
    public List<Carpiecename> pieceList(Model model, String modelNo){
        List<Carpiecename> piecenameList = shoppingService.piecenameList(modelNo);
        return piecenameList;
    }

    @RequestMapping("/accessinfoList")
    @ResponseBody
    public List<Accessinfo> accessinfoList(Model model,String pieceNo){
        List<Accessinfo> accessinfoList = shoppingService.accessinfoList(pieceNo);
        System.out.println(accessinfoList.size());
        return accessinfoList;
    }

    @RequestMapping("/carlist")
    public String shoppingcar(Model model,String seriesName,String modelName,String pieceName,String pieceNo){
        OrderCar orderCar = new OrderCar();
        orderCar.setSeriesName(seriesName);
        orderCar.setModelName(modelName);
        orderCar.setPieceName(pieceName);
        List<Accessinfo> accessinfoList = shoppingService.accessinfoList(pieceNo);
        orderCar.setAccessinfoList(accessinfoList);
        model.addAttribute("orderCar",orderCar);
        return "/Business/Order_Enterprise/Temporary_Order_List";
    }

}
